package sgd.tp2.server.metrics;

public class Statistics {

	long sum = 0;
	long n = 0;
	long ssum = 0;
	long max;
	long min = -1;

	public long getN() {
		return n;
	}

	public long getMax() {
		return max;
	}

	public void setMax(long max) {
		this.max = max;
	}

	public long getMin() {
		return min;
	}

	public void setMin(long min) {
		this.min = min;
	}

	public void addValue(long value) {
		n++;
		sum += value;
		ssum += (value * value);
		max = Math.max(max, value);
		if (min > -1)
			min = Math.min(min, value);
		else
			min = value;
	}

	public float getAverage() {
		return  sum / n;
	}
	
	public float getAverageRounded() {
		return Math.round(getAverage());
	}

	public double getStandardDeviation() {
		return Math.sqrt((double) ssum / (double) n - getAverage() * getAverage());
	}
	
	public double getStandardDeviationRounded() {
		return Math.round(getStandardDeviation());
	}

	public void printStatistics() {
		System.out.println("N = " + n);
		System.out.println("sum = " + sum);
		System.out.println("ssum = " + ssum);
		System.out.println("max = " + max);
		System.out.println("min = " + min);
		System.out.println("avg = " + getAverage());
		System.out.println("stdev = " + getStandardDeviation());
	}
}
